<?php
class basicTest_data extends model
{
    
    const ValidRule_id_test_data_isInt = 'ValidRule-id_test_data-isInt';
    const ValidRule_id_test_data_exists = 'ValidRule-id_test_data-exists';
    const ValidRule_dateFrom_isDateTime = 'ValidRule-dateFrom-isDateTime';
    const ValidRule_dateFrom_exists = 'ValidRule-dateFrom-exists';
    const ValidRule_dateTo_isDateTime = 'ValidRule-dateTo-isDateTime';
    const ValidRule_dateTo_exists = 'ValidRule-dateTo-exists';
    const ValidRule_id_instrument_isInt = 'ValidRule-id_instrument-isInt';
    const ValidRule_id_instrument_exists = 'ValidRule-id_instrument-exists';
    const ValidRule_name_exists = 'ValidRule-name-exists';
    const ValidRule_name_isTextPl = 'ValidRule-name-isTextPl';
    const ValidRule_file_exists = 'ValidRule-file-exists';

	
    public $id_test_data;
    public $number;
    public $dateTo;
    public $id_instrument;
    public $name;
    public $file;
    public $data_in;
    public $data_out;
    public $number_in;
    public $number_out;


	public static function loadModel($id=null, $join=null)
	{
		$obiekt = new Test_data($id, $join);
		if(!$obiekt ->isNull())
			return $obiekt;
		else return null;
	}
				
	public static function loadSpecialModel($where){
		$stmt = self::$pdo -> query("SELECT * FROM Test_data WHERE $where LIMIT 1;");
		$row = $stmt -> fetch(PDO::FETCH_ASSOC);
		if(!$row)
			return self::loadModel();
		$model = self::loadModel();
		$model -> SetValues($row);
		$model -> NewRecord = false;
		return $model;
	}

	public static function getAll($where=null)
	{
		return model::getAll('Test_data', $where);
	}

	public function __construct($id=null, $join = null)
	{
		parent::__construct($id, $join);
		$this -> labels = array(
            'id_test_data' => 'id_test_data', 
            'number' => 'number',
            'dateTo' => 'dateTo', 
            'id_instrument' => 'id_instrument', 
            'name' => 'name', 
            'file' => 'file',
            'data_in' => 'data_in',
            'data_out' => 'data_out',
            'number_in' => 'number in',
            'number_out' => 'number_out'
        );
	}

		
	public function getTableName()
	{
		return 'Test_data';
	}

	public function getPrimaryKey()
	{
		return 'id_test_data';
	}

	public function getColumns()
	{
		return array('id_test_data', 'number', 'dateTo', 'id_instrument', 'name', 'file','data_in', 'data_out', 'number_in', 'number_out');
	}

	protected function getBoolColumns()
	{
		return array();
	}

	public function getRules($ignore=array())
	{
		$rules = array(
            'ValidRule-id_test_data-isInt' => new ValidRule('id_test_data', isInt, array(&$this->id_test_data)),
            'ValidRule-id_test_data-exists' => new ValidRule('id_test_data', exists, array(&$this->id_test_data)),
            'ValidRule-dateFrom-isDateTime' => new ValidRule('dateFrom', isDateTime, array(&$this->dateFrom)),
            'ValidRule-dateFrom-exists' => new ValidRule('dateFrom', exists, array(&$this->dateFrom)),
            'ValidRule-dateTo-isDateTime' => new ValidRule('dateTo', isDateTime, array(&$this->dateTo)),
            'ValidRule-dateTo-exists' => new ValidRule('dateTo', exists, array(&$this->dateTo)),
            'ValidRule-id_instrument-isInt' => new ValidRule('id_instrument', isInt, array(&$this->id_instrument)),
            'ValidRule-id_instrument-exists' => new ValidRule('id_instrument', exists, array(&$this->id_instrument)),
            'ValidRule-name-exists' => new ValidRule('name', exists, array(&$this->name)),
            'ValidRule-name-isTextPl' => new ValidRule('name', isTextPl, array(&$this->name)),
            'ValidRule-file-exists' => new ValidRule('file', exists, array(&$this->file))	
        );			

		if(!empty($ignore))
		{
			if(!is_array($ignore)) $ignore = array($ignore);
			foreach($ignore as $field)
			{
				unset($rules[$field]);
			}
		}
		return $rules;

	}

    protected function getJoinTables() {
        return array('instrument');
    }


}
?>